require(['./loading_img','subtitle','../lib/jquery-easing','./shakesnow'],function(mod_load,subtitle,easing,modshake) {
    $('.ui-loader').remove();
    $('body').removeClass('.ui-mobile-viewport').removeClass('..ui-overlay-a');

    var shake = modshake.shake;
    var audioControl = modshake;
    var playControl = modshake;
    //loading 图片预加载路径
    var iMagesUrl = [
        './images/m_ban.png'
    ];

    mod_load.loading(iMagesUrl, function () {
        $(".mod-dialog-loading").hide();
        audioControl.initplay($("#before"));
        $(".redball").addClass("ballrotate");
        $(".yellowball").addClass("ballrotate");
        $(".blueball").addClass("ballrotate");
        setTimeout(function () {
            $(".za_logo").show();
            $(".za_logo").stop().animate({"top": "-1.95rem"}, {
                easing: "bounceOut",
                duration: 1000,
                complete: function () {
                    $(".za_shadow").fadeIn();
                    setTimeout(function () {
                        subtitle.subtitle($(".mod-info").find("p"), 1399, subtitleCb)
                    }, 1000)
                }
            })
        }, 3500)
    });
    playControl.playControl();
    function subtitleCb() {
        $(".mod-info").fadeOut();
        subtitle.subtitle($(".man"), 900, personCb);
        function personCb() {
            $(".bottomword").find(".b-word").show();
            $(".bottomword").find(".b-word").addClass("breath");
            BackEarth()
        }
    }

    var sceneStatus;

    //touch up

    function santeUp(callback){
        var page2 = $("body");//jQuery对象page2
        var hammerPage2 = new Hammer(page2[0]);
        hammerPage2.on('swipeup',function(ev){
            callback&&callback();
        });
        $('body')[0].addEventListener('touchmove',function(ev){
            ev.preventDefault();
        },false);
    }

    function setHideSize(obj){
        //if($(obj).attr('Bestlock')=='true')return;
        //$(obj).attr('Bestlock','false');
        if(!obj.paused){
            return;
        }
        console.log('hide');
        obj.style.width='1px';
        obj.style.height='1px';
        //$('.videobox').css({width:'100%',left:'0'});
        $('.videobox').css('zIndex','-10000');
    }
    function setShowsize(obj){
        //if($(obj).attr('Bestlock')=='false')return;
        //$(obj).attr('Bestlock')=='true'
        obj.style.width='100%';
        obj.style.height=29*20/0.5625+'px';
        console.log(obj.offsetHeight);
        obj.style.marginTop=-28.45*20*0.355+'px';
        //obj.style.height='100%';
        $('.videobox').css({'zIndex':10000});
    }
    //}
    function playAgain(obj){
        for(var i=0;i<obj.size();i++){
            obj.eq(i).on('tap',function(){
                sceneStatus = $(this).attr('id');
                var obj = document.getElementById($(this).attr('data-view'));
                console.log(obj);
                playVideo();
            });
        }
    }
    //playAgain($('.part'));

    $('.allen').on('tap',function(){
        sceneStatus = $(this).attr('id');
        var obj = document.getElementById($(this).attr('data-view'));
        console.log(sceneStatus);
        playVideo();
        return false;
    })
    $('.ben').on('tap',function(){
        sceneStatus = $(this).attr('id');
        var obj = document.getElementById($(this).attr('data-view'));
        console.log(obj);
        playVideo();
        return false;
    })
    $('.carl').on('tap',function(){
        sceneStatus = $(this).attr('id');
        var obj = document.getElementById($(this).attr('data-view'));
        console.log(obj);
        playVideo();
        return false;
    })
    $('.danny').on('tap',function(){
        sceneStatus = $(this).attr('id');
        var obj = document.getElementById($(this).attr('data-view'));
        console.log(obj);
        playVideo();
        return false;
    })
    //initV();
    var oBjYY = document.getElementById('video1');
    var oBjJJH = document.getElementById('video2');
    var oBjXB = document.getElementById('video3');
    var oBjJK = document.getElementById('video4');
    $(oBjYY).on('click',function(ev){
        //if(!oBjYY.paused){
        oBjYY.pause();
        setHideSize(oBjYY);
        //oBjYY.pause();
        //}
        ev.stopPropagation();
        return false;
    });
    $(oBjJJH).on('click',function(ev){
        oBjJJH.pause();
        setHideSize(oBjJJH);
        ev.stopPropagation();
        return false;
    });
    $(oBjJK).on('click',function(ev){
        oBjJK.pause();
        setHideSize(oBjJK);
        ev.stopPropagation();
        return false;
    });
    $(oBjXB).on('click',function(ev){
        oBjXB.pause();
        setHideSize(oBjXB);
        ev.stopPropagation();
        return false;
    });
    function playVideo(){

        $('.videobox').css({'zIndex':10000});

        switch (sceneStatus){
            case 'yydr':
                setShowsize(oBjYY);
                oBjYY.play();
                //if(Number(oBjYY.currentTime)>=Number(oBjYY.duration-1)){
                //    oBjYY.pause();
                //    oBjYY.currentTime = 0;
                //    setHideSize(oBjYY);
                //    console.log('123123123');
                //
                //}
                oBjYY.addEventListener('ended',function(){
                    oBjYY.currentTime = 0;
                    console.log(11);
                    setHideSize(oBjYY);
                },false);
                oBjYY.addEventListener('pause',function(){
                    if(!oBjJK.paused){
                        oBjJK.currentTime = 0;
                        //oBjYY.pause();
                    }
                },false);

                break;
            case 'jjh':
                setShowsize(oBjJJH);
                oBjJJH.play();
                oBjJJH.addEventListener('ended',function(){
                    oBjYY.currentTime = 0;
                    console.log(11);
                    setHideSize(oBjJJH);
                },false);
                oBjJJH.addEventListener('pause',function(){
                    if(!oBjJJH.paused){
                        oBjJJH.currentTime = 0;
                        //oBjYY.pause();
                    }
                },false);
                break;
            case 'xb':
                setShowsize(oBjXB);
                oBjXB.play();
                oBjXB.addEventListener('ended',function(){
                    oBjXB.currentTime = 0;
                    setHideSize(oBjXB);
                },false);
                oBjXB.addEventListener('pause',function(){
                    if(!oBjXB.paused){
                        oBjXB.currentTime = 0;
                        //oBjYY.pause();
                    }
                },false);
                break;
            case 'jk':
                setShowsize(oBjJK);
                oBjJK.play();
                oBjJK.addEventListener('ended',function(){
                    oBjJK.currentTime = 0;
                    setHideSize(oBjXB);
                },false);
                oBjJK.addEventListener('pause',function(){
                    if(!oBjJK.paused){
                        oBjJK.currentTime = 0;
                        //oBjYY.pause();
                    }
                },false);
                break;
        }
    }

    function BackEarth() {
        $(".persons").find(".man").on("tap", function () {
            sceneStatus = $(this).find(".face").attr("data-status");
            console.log(sceneStatus);
            $(".starrysky").addClass("move");
            setTimeout(function () {
                $(".starrysky").addClass("move-complete")
            }, 2999);
            setTimeout(function () {
                $("#sky-box").stop().fadeOut();
                setTimeout(function () {

                    $('.earth').stop().fadeIn();
                    shakephone()
                }, 800)
            }, 600)
        })
    }

    function signStatus() {
        var signindex;
        var indexarr = [];
        switch (sceneStatus) {
            case"yydr":
                signindex = 0;
                break;
            case"jjh":
                signindex = 1;
                break;
            case"xb":
                signindex = 2;
                break;
            case"jk":
                signindex = 3;
                break
        }
        for (var i = 0; i < 4; i++) {
            indexarr.push(signindex % 4);
            signindex = signindex + 1
        }
        return indexarr
    }

    function shakephone() {
        shake(function (c) {
            audioControl.audioplay($("#shake"));
            $(".earth_bg").find(".b-word").stop().fadeOut();
            $("body").append(c);
            setTimeout(function () {
                $(".earth_snow").addClass("snowin");
                setTimeout(function () {
                    $(".earth_snow").removeClass("snowin");
                    $(".earth_snow").addClass("onsnow");
                    $(".earth").addClass("movenear");
                    setTimeout(function () {
                        $(".earth").addClass("movenear-complete")
                    }, 2999);
                    setTimeout(function () {
                        $(".earth").fadeOut();
                        setTimeout(function () {
                            $(".santa-man").fadeIn(1000, function () {
                                setTimeout(function () {
                                    $(".santa-light").fadeIn(1000, lightend);
                                    function lightend() {
                                        $(".santa-oldman").fadeIn();
                                        $(".santa-oldman").addClass("onland");
                                        setTimeout(function () {
                                            $(".santa-oldman").removeClass("santa-fly").addClass("santa-land").addClass("landed");
                                            $('.santafly-msg').fadeIn();
                                            santeUp(function(){
                                                $(".santa-oldman").fadeOut();
                                                $(".santaonsled").fadeIn();
                                                $(".sled-bg").fadeOut();
                                                $(".sled").addClass("sledfly");
                                                setTimeout(function () {
                                                    $(".sled").fadeOut(1000, sceneBegin);
                                                    $("body").attr("data-status", "on");
                                                    function sceneBegin() {
                                                        $(c).remove();
                                                        $(".santa-man").fadeOut();
                                                        function sceneshow() {
                                                            activeindex = signStatus();
                                                            var swipelock = false;
                                                            var swipecount = 0;
                                                            var obj = $("div[sign-status='1']").eq(activeindex[0]);
                                                            playVideo();
                                                            $('.videoplay').fadeIn();
                                                        }
                                                        sceneshow()
                                                    }
                                                }, 2000)
                                            });
                                        }, 2999)
                                    }
                                }, 1000)
                            })
                        }, 800)
                    }, 1500)
                }, 2999)
            }, 1400)
        })
    }

    var WISHCON = "";

    function transfromwish() {
        $('.videoplay-bg').find('.msg').on('click',function(){
            $('.videoplay').fadeOut();
            $(".wish").fadeIn(1000, function () {
                wishBegin()
            })
        });
    }
    transfromwish();
    function wishBegin() {
        subtitle.subtitle($(".wish-content"), 1000, function () {
            $(".wish-bigballcon").fadeIn(1000, function () {
                $(".wish-bigballtop").slideDown(1000, function () {
                    $(".wish-bigballbot").fadeIn(function () {
                        $(".wish-z").addClass("breath");
                        $(".wish-wishbtn").fadeIn(1000);
                        $(".wish-prompt").fadeIn(1000, function () {
                            $(".wish-word").fadeOut(1000);
                            $(".small-ball1").fadeIn(1000);
                            $(".small-ball2").fadeIn(1000);
                            $(".small-ball2").addClass("radius");
                            setTimeout(function () {
                                $(".small-ball1").addClass("radius")
                            }, 500)
                        })
                    })
                })
            });
            $(".wish-makewish").click(function () {
                $(".wish-writebg").show();
                $(".wish-write textarea").focus().text("")
            });
            $(".wish-writeclose").click(function () {
                $(".wish-writebg").hide()
            });
            $(".wish-pushchi").click(function () {
                WISHCON = $(".wish-write textarea").val();
                $(".wish-bg").hide();
                $(".wish-radar").show()
            });
            $(".wish-Invit-makewish").click(function () {
                var str = window.location.href;
                WISHHREF = str + "#Letmakewish";
                window.location.href = WISHHREF;
                $(".wish-share-to").show()
            });
            $(".wish-share-to").click(function () {
                $(this).hide()
            });
            $(".wish-friendwrite").click(function () {
                var str = window.location.href;
                if (str.charAt("#") != -1) {
                    str = str.substring(str.charAt("#"))
                }
                WISHHREF = str + "#Letmeet";
                window.location.href = WISHHREF;
                $(".wish-share-to").show()
            });
            $(".wish-clickbtn").click(function () {
                $(this).hide();
                function shownum() {
                    var n = ran(1, 5);
                    var str = ".person" + n;
                    showPerson($(str))
                }

                setTimeout(function () {
                    var m = ran(1, 5);
                    for (var i = 0; i < m; i++) {
                        shownum()
                    }
                }, 800);
                setTimeout(function () {
                    $(".wish-invitation-code").show();
                    $(".wish-invitation-code").html(getCode());
                    $(".wish-code-con1").show();
                    $(".wish-code-con2").show();
                    $(".wish-sendall").show()
                }, 1000)
            })
        });
        $(".wish-sendall").click(function () {
            $(".wish-radar").hide();
            $(".wish-mywish").show();
            $(".wish-mywish-text").val(WISHCON);
            var ua = navigator.userAgent.toLowerCase();
            if (/iphone|ipad|ipod/.test(ua)) {
                $(".wish-mywish").css("background-image", 'url("images/wish-mywishios.png")');
                $(".wish-mywish-reload").hide();
                $(".wish-mywish-share").css("left", "8.25rem")
            } else {
                if (/android/.test(ua)) {
                    $(".wish-mywish").css("background-image", 'url("images/wish-mywish2.png")')
                }
            }
        });
        $(".wish-mywish-close").click(function () {
            $(".wish-radar").show();
            $(".wish-mywish").hide()
        });
        $(".wish-share-to2").click(function () {
            this.hide()
        });
        $(".wish-mywish-reload").click(function () {
            if (isWeiXin()) {
                $(".wish-share-to2").show()
            } else {
                window.location.href = "http://downloadb.dewmobile.net/Zapya/Activity/Apk/Kuaiya.apk"
            }
            function isWeiXin() {
                var ua = window.navigator.userAgent.toLowerCase();
                if (ua.match(/MicroMessenger/i) == "micromessenger") {
                    return true
                } else {
                    return false
                }
            }
        });
        $(".wish-mywish-share").click(function () {
            $(".wish-share-to").show()
        });
        $(".small-ball1").click(function () {
            $(".wish-bg").hide();
            $(".wish-radar").show()
        });
        $(".small-ball2").click(function () {
            $(".wish-bg").hide();
            $(".wish-radar").show()
        });
        function showPerson(obj) {
            var arr = [{
                name: "妹子撩骚了",
                href: "http://avatar.kuaiya.cn/FlrVtAfGLSOYIg5vsgQ64E3HAXaV/tbnl?e=1794724262"
            }, {
                name: "诛仙青云志",
                href: "http://avatar.kuaiya.cn/FmytphDDVH5Gspevw9jV26tkg3_O/tbnl?e=1785567240"
            }, {
                name: "陈二狗重回孽障人生",
                href: "http://avatar.kuaiya.cn/FpX2fV2DSSO6TS4Kiaga_2_-VeGM/tbnl?e=1795675998"
            }, {
                name: "22岁的未成年",
                href: "http://avatar.kuaiya.cn/FhzEil1y-7tRoO6LwiWCMnNm7pwT/tbnl?e=1795855841"
            }, {
                name: "话说飞刀又见飞刀",
                href: "http://avatar.kuaiya.cn/FrJZijsIOvEZlHjGt8pciSMrzyB3/tbnl?e=1796462628"
            }, {
                name: "超好看的热门网剧",
                href: "http://avatar.kuaiya.cn/FouO5h8CJUmAleiS7p--cSv0haAO/tbnl?e=1796355402"
            }, {
                name: "不良人的极品家丁",
                href: "http://avatar.kuaiya.cn/FvG0tRUxgeUZAtQb_fgqzmppJZDz/tbnl?e=1796367253"
            }, {
                name: "微影",
                href: "http://avatar.kuaiya.cn/FpWBIhifFL4iIeYxn4z5qroPvMns/tbnl?e=1772360804"
            }, {
                name: "拜托了学妹",
                href: "http://avatar.kuaiya.cn/FlZkgC7wr8eHQcYbKgOb8U8KpnCi/tbnl?e=1795855153"
            }, {name: "夜色撩人", href: "http://avatar.kuaiya.cn/FsuHJc0a-fj6OgbN9SeJSf1k8A5m/tbnl?e=1773992092"}];
            obj.show();
            obj.find("img").attr("src", arr[ran(0, 10)].href);
            obj.find("span").html(arr[ran(0, 10)].name)
        }

        function ran(n, m) {
            return Math.floor(Math.random() * (m - n) + n)
        }

        function getCode() {
            var arr = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "s", "y", "z"];
            return "Z" + ran(1, 8) + ran(1, 8) + "A" + ran(2, 9) + ran(2, 8) + "P" + ran(3, 10) + ran(3, 10) + "YA" + arr[ran(0, 26)] + arr[ran(0, 26)]
        }
    };

});








